home *** CD-ROM | disk | FTP | other *** search
- /*
- * The original copyright owners of the accompanying source code files have
- * agreed to place such code into the public domain. Accordingly, anyone
- * who receives or obtains a copy of such source code is freely entitled to
- * reproduce, use and otherwise exploit such code (including the right to
- * make derivative works), at his/her own risk and expense, without any
- * obligation or liability to the original copyright owners.
- *
- * We would appreciate (but do not require) that the following message be
- * included in any derivative works:
- *
- * "Portions of this program were developed by Peter Broadwell, Rob Myers
- * and Robin Schaufler while working in Silicon Valley."
- *
- * The accompanying source code files and related documentation materials
- * are distributed on an "AS IS" basis, without any warranties or
- * guarantees of any kind. All implied warranties, including the implied
- * warranties of merchantability and of fitness for any particular purpose,
- * are expressly disclaimed.
- */
- #include "gl.h"
- #include "geom.h"
- #include "class.h"
- #include "selectors.h"
- #include "classIds.h"
- #include "mbox.h"
- #include "individual.h"
- #include "colors.h"
- #include "camera.h"
- #include "panel.h"
- #include "valuator.h"
- #include "pick.h"
-
- extern inst *clone();
-
- extern valuator valTemplate;
- extern valuatorf valfTemplate;
- extern valdelta valDeltaTemplate;
- extern valdeltaf valDeltafTemplate;
- extern valmesg valMesgTemplate;
- extern valmesgf valMesgfTemplate;
- extern valhue valHueTemplate;
- extern valval valValTemplate;
-
- /*
- * initialize a valuator
- */
- panel *
- makeValuator(list, dad, f, ScrArea, clampIn, WorldArea, xVal, yVal, pObj, tObj)
- register panel *list, *dad;
- int f;
- register rectangle *ScrArea;
- register point2d *clampIn;
- register rectangle *WorldArea;
- int *xVal, *yVal;
- Object pObj, tObj;
- {
- register valuator *aValuator;
-
- if ((aValuator = (valuator *)clone(&valTemplate)) == NULL)
- return list;
-
- aValuator->base.next = list;
- aValuator->base.kids = NULL;
- aValuator->base.dad = dad;
- aValuator->base.area = *ScrArea;
- aValuator->base.painter = pObj;
-
- aValuator->flags = f;
- setClamp(&aValuator->clamp, ScrArea, clampIn);
- aValuator->world = *WorldArea;
- aValuator->xVal = xVal;
- aValuator->yVal = yVal;
- aValuator->tracker = tObj;
-
- return (panel *)aValuator;
- }
-
-
- /*
- * initialize a floating point valuator
- */
- panel *
- makeValuatorf(list, dad, f, ScrArea, clampIn, WorldArea, xVal, yVal, pObj, tObj)
- register panel *list, *dad;
- int f;
- register rectangle *ScrArea;
- register point2d *clampIn;
- register rectanglef *WorldArea;
- Coord *xVal, *yVal;
- Object pObj, tObj;
- {
- register valuatorf *aValuator;
-
- if ((aValuator = (valuatorf *)clone(&valfTemplate)) == NULL)
- return list;
-
- aValuator->base.next = list;
- aValuator->base.kids = NULL;
- aValuator->base.dad = dad;
- aValuator->base.area = *ScrArea;
- aValuator->base.painter = pObj;
-
- aValuator->flags = f;
- setClamp(&aValuator->clamp, ScrArea, clampIn);
- aValuator->world = *WorldArea;
- aValuator->xVal = xVal;
- aValuator->yVal = yVal;
- aValuator->tracker = tObj;
-
- return (panel *)aValuator;
- }
-
- /*
- * initialize a delta valuator
- */
- panel *
- makeValDelta(list, dad, f, ScrArea, clampIn, WorldArea, xVal, yVal, Limits,pObj)
- register panel *list, *dad;
- int f;
- register rectangle *ScrArea;
- register point2d *clampIn;
- register rectangle *WorldArea;
- int *xVal, *yVal;
- register rectangle *Limits;
- Object pObj;
- {
- register valdelta *aValuator;
-
- if ((aValuator = (valdelta *)clone(&valDeltaTemplate)) == NULL)
- return list;
-
- aValuator->base.next = list;
- aValuator->base.kids = NULL;
- aValuator->base.dad = dad;
- aValuator->base.area = *ScrArea;
- aValuator->base.painter = pObj;
-
- aValuator->flags = f;
- setClamp(&aValuator->clamp, ScrArea, clampIn);
- aValuator->world = *WorldArea;
- aValuator->xVal = xVal;
- aValuator->yVal = yVal;
- aValuator->limits = *Limits;
-
- return (panel *)aValuator;
- }
-
- /*
- * initialize a floating point delta valuator
- */
- panel *
- makeValDeltaf(list, dad, f, ScrArea, clampIn, WorldArea, xVal, yVal,Limits,pObj)
- register panel *list, *dad;
- int f;
- register rectangle *ScrArea;
- register point2d *clampIn;
- register rectanglef *WorldArea;
- Coord *xVal, *yVal;
- register rectanglef *Limits;
- Object pObj;
- {
- register valdeltaf *aValuator;
-
- if ((aValuator = (valdeltaf *)clone(&valDeltafTemplate)) == NULL)
- return list;
-
- aValuator->base.next = list;
- aValuator->base.kids = NULL;
- aValuator->base.dad = dad;
- aValuator->base.area = *ScrArea;
- aValuator->base.painter = pObj;
-
- aValuator->flags = f;
- setClamp(&aValuator->clamp, ScrArea, clampIn);
- aValuator->world = *WorldArea;
- aValuator->xVal = xVal;
- aValuator->yVal = yVal;
- aValuator->limits = *Limits;
-
- return (panel *)aValuator;
- }
-
-
- /*
- * initialize a message-sending valuator
- */
- panel *
- makeValMesg(list, dad, f, ScrArea, clampIn, WorldArea, x,y, rec,sel,r,pObj,tObj)
- register panel *list, *dad;
- int f;
- register rectangle *ScrArea;
- register point2d *clampIn;
- register rectangle *WorldArea;
- int x, y;
- inst *rec;
- int sel;
- int r;
- Object pObj, tObj;
- {
- register valmesg *aValuator;
-
- if ((aValuator = (valmesg *)clone(&valMesgTemplate)) == NULL)
- return list;
-
- aValuator->base.next = list;
- aValuator->base.kids = NULL;
- aValuator->base.dad = dad;
- aValuator->base.area = *ScrArea;
- aValuator->base.painter = pObj;
-
- aValuator->flags = f;
- setClamp(&aValuator->clamp, ScrArea, clampIn);
- aValuator->world = *WorldArea;
- aValuator->val.x = x;
- aValuator->val.y = y;
- aValuator->receiver= rec;
- aValuator->selector= sel;
- aValuator->reset = r;
- aValuator->tracker = tObj;
-
- return (panel *)aValuator;
- }
-
- /*
- * initialize a floating point message-sending valuator
- */
- panel *
- makeValMesgf(list, dad, f, ScrArea, clampIn, WorldArea, x,y,rec,sel,r,pObj,tObj)
- register panel *list, *dad;
- int f;
- register rectangle *ScrArea;
- register point2d *clampIn;
- register rectanglef *WorldArea;
- Coord x, y;
- inst *rec;
- int sel;
- int r;
- Object pObj, tObj;
- {
- register valmesgf *aValuator;
-
- if ((aValuator = (valmesgf *)clone(&valMesgfTemplate)) == NULL)
- return list;
-
- aValuator->base.next = list;
- aValuator->base.kids = NULL;
- aValuator->base.dad = dad;
- aValuator->base.area = *ScrArea;
- aValuator->base.painter = pObj;
-
- aValuator->flags = f;
- setClamp(&aValuator->clamp, ScrArea, clampIn);
- aValuator->world = *WorldArea;
- aValuator->val.x = x;
- aValuator->val.y = y;
- aValuator->receiver= rec;
- aValuator->selector= sel;
- aValuator->reset = r;
- aValuator->tracker = tObj;
-
- return (panel *)aValuator;
- }
-
- panel *
- makeValHue(list, dad, f, ScrArea, clampIn, color, hueId, showId)
- register panel *list, *dad;
- int f;
- register rectangle *ScrArea;
- register point2d *clampIn;
- int color;
- Object hueId, showId;
- {
- register valhue *aValuator;
-
- if ((aValuator = (valhue *)clone(&valHueTemplate)) == NULL)
- return list;
-
- aValuator->base.next = list;
- aValuator->base.kids = NULL;
- aValuator->base.dad = dad;
- aValuator->base.area = *ScrArea;
- aValuator->base.painter = hueId;
-
- aValuator->flags = f;
- setClamp(&aValuator->clamp, ScrArea, clampIn);
- aValuator->world.orig.x = 0;
- aValuator->world.orig.y = 0;
- aValuator->world.extent.x = MAXHUE;
- aValuator->world.extent.y = MAXSAT;
- aValuator->display = showId;
-
- return (panel *)aValuator;
- }
-
- panel *
- makeValVal(list, dad, f, ScrArea, clampIn, color, valId, showId)
- register panel *list, *dad;
- int f;
- register rectangle *ScrArea;
- register point2d *clampIn;
- int color;
- Object valId, showId;
- {
- register valval *aValuator;
-
- if ((aValuator = (valval *)clone(&valValTemplate)) == NULL)
- return list;
-
- aValuator->base.next = list;
- aValuator->base.kids = NULL;
- aValuator->base.dad = dad;
- aValuator->base.area = *ScrArea;
- aValuator->base.painter = valId;
-
- aValuator->flags = f;
- setClamp(&aValuator->clamp, ScrArea, clampIn);
- aValuator->world.orig.x = 0;
- aValuator->world.orig.y = 0;
- aValuator->world.extent.x = 0;
- aValuator->world.extent.y = MAXVAL;
- aValuator->display = showId;
-
- return (panel *)aValuator;
- }
-
- setClamp(clampRect, rawRect, inset)
- register rectangle *clampRect, *rawRect;
- register point2d *inset;
- {
- clampRect->orig.x = inset->x;
- clampRect->orig.y = inset->y;
- clampRect->extent.x = rawRect->extent.x - (2 * inset->x);
- clampRect->extent.y = rawRect->extent.y - (2 * inset->y);
- }
-
- #define interp(a,b,c,d) (((float)(a)/(float)(b)*(float)(c))+(float)(d))
-
- /*
- * draw a valuator's tracker at its current position
- */
- drawVal(v)
- register valuator *v;
- {
- point2df curP;
-
- if (v->tracker) {
- if ((v->world.extent.x != 0) && v->xVal)
- curP.x = interp(*(v->xVal) - v->world.orig.x, v->world.extent.x,
- v->clamp.extent.x, v->clamp.orig.x);
- else curP.x = ((float)v->clamp.extent.x/2.0) + (float)v->clamp.orig.x;
-
- if ((v->world.extent.y != 0) && v->yVal)
- curP.y = interp(*(v->yVal) - v->world.orig.y, v->world.extent.y,
- v->clamp.extent.y, v->clamp.orig.y);
- else curP.y = ((float)v->clamp.extent.y/2.0) + (float)v->clamp.orig.y;
-
- translate(curP.x, curP.y, 0.0);
- callobj(v->tracker);
- }
- }
-
-
- /*
- * draw a floating point valuator's tracker at its current position
- */
- drawValf(v)
- register valuatorf *v;
- {
- point2df curP;
-
- if (v->tracker) {
- if ((v->world.extent.x != 0) && v->xVal)
- curP.x = interp(*(v->xVal) - v->world.orig.x, v->world.extent.x,
- v->clamp.extent.x, v->clamp.orig.x);
- else curP.x = ((float)v->clamp.extent.x/2.0) + (float)v->clamp.orig.x;
-
- if ((v->world.extent.y != 0) && v->yVal)
- curP.y = interp(*(v->yVal) - v->world.orig.y, v->world.extent.y,
- v->clamp.extent.y, v->clamp.orig.y);
- else curP.y = ((float)v->clamp.extent.y/2.0) + (float)v->clamp.orig.y;
-
- translate(curP.x, curP.y, 0.0);
- callobj(v->tracker);
- }
- }
-
- /*
- * draw a message valuator's tracker at its current position
- */
- drawValMesg(v)
- register valmesg *v;
- {
- point2df curP;
-
- if (v->tracker) {
- if (v->world.extent.x != 0)
- curP.x = interp(v->val.x - v->world.orig.x, v->world.extent.x,
- v->clamp.extent.x, v->clamp.orig.x);
- else curP.x = ((float)v->clamp.extent.x/2.0) + (float)v->clamp.orig.x;
-
- if (v->world.extent.y != 0)
- curP.y = interp(v->val.y - v->world.orig.y, v->world.extent.y,
- v->clamp.extent.y, v->clamp.orig.y);
- else curP.y = ((float)v->clamp.extent.y/2.0) + (float)v->clamp.orig.y;
-
- translate(curP.x, curP.y, 0.0);
- callobj(v->tracker);
- }
- }
-
-
- /*
- * draw a floating point message valuator's tracker at its current position
- */
- drawValMesgf(v)
- register valmesgf *v;
- {
- point2df curP;
-
- if (v->tracker) {
- if (v->world.extent.x != 0.0)
- curP.x = interp(v->val.x - v->world.orig.x, v->world.extent.x,
- v->clamp.extent.x, v->clamp.orig.x);
- else curP.x = ((float)v->clamp.extent.x/2.0) + (float)v->clamp.orig.x;
-
- if (v->world.extent.y != 0.0)
- curP.y = interp(v->val.y - v->world.orig.y, v->world.extent.y,
- v->clamp.extent.y, v->clamp.orig.y);
- else curP.y = ((float)v->clamp.extent.y/2.0) + (float)v->clamp.orig.x;
-
- translate(curP.x, curP.y, 0.0);
- callobj(v->tracker);
- }
- }
-
- /*
- * draw a valuator's tracker at its current position
- */
- drawColorVal(v)
- register valval *v;
- {
- RGBvalue r, g, b;
- colorPanel *dad;
-
- if (dad = (colorPanel *)v->base.dad) {
- /* map from hsv to rgb; */
- /* dad->hue, dad->satur, dad->value */
- /* mapcaller(dad->clientColor, r, g, b); */
- callobj(v->display);
- }
- }
-
-
- /*
- * reset message valuator to orig
- */
- resetValMesg(v, argtype, hit)
- register valmesg *v;
- long argtype;
- hitstruct *hit;
- {
- /* printf("resetValMesg: reset=%d\n", v->reset); /* */
-
- if (v->reset == AUTORESET) {
- v->val.x = 0;
- v->val.y = 0;
- }
- }
-
-
- /*
- * reset floating point message valuator to orig
- */
- resetValMesgf(v, argtype, hit)
- register valmesgf *v;
- long argtype;
- hitstruct *hit;
- {
- /* printf("resetValMesgf: reset=%d\n", v->reset); /* */
-
- if (v->reset == AUTORESET) {
- v->val.x = 0.0;
- v->val.y = 0.0;
- }
- }
-
-
- /*
- * process a selection on a valuator
- */
- selectVal(self, argtype, hit)
- register valuator *self;
- long argtype;
- register hitstruct *hit;
- {
- if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
- return;
-
- if (self->xVal) {
- *(self->xVal) = (int)((float)(hit->x * self->world.extent.x) /
- (float)self->clamp.extent.x) + self->world.orig.x;
- /* printf("selectVal: xVal=%d\n", *(self->xVal));
- /* */
- }
- if (self->yVal) {
- *(self->yVal) = (int)((float)(hit->y * self->world.extent.y) /
- (float)self->clamp.extent.y) + self->world.orig.y;
- /* printf("selectVal: yVal=%d\n", *(self->yVal));
- /* */
- }
- }
-
-
- /*
- * process a selection on a floating point valuator
- */
- selectValf(self, argtype, hit)
- register valuatorf *self;
- long argtype;
- register hitstruct *hit;
- {
- if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
- return;
-
- if (self->xVal) {
- *(self->xVal) = (((float)hit->x * self->world.extent.x) /
- (float)self->clamp.extent.x)+self->world.orig.x;
- /* printf("selectValf: xVal=%g\n", *(self->xVal));
- /* */
- }
- if (self->yVal) {
- *(self->yVal) = (((float)hit->y * self->world.extent.y) /
- (float)self->clamp.extent.y)+self->world.orig.y;
- /* printf("selectValf: yVal=%g\n", *(self->yVal));
- /* */
- }
- }
-
- /*
- * process a selection on a delta valuator
- */
- selectValDelta(self, argtype, hit)
- register valdelta *self;
- long argtype;
- register hitstruct *hit;
- {
- if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
- return;
-
- if (self->xVal) {
- *(self->xVal) += (int)((float)(hit->x * self->world.extent.x) /
- (float)self->clamp.extent.x) + self->world.orig.x;
- clamp(self->xVal, self->limits.orig.x, self->limits.extent.x);
- /* printf("selectValDelta: xVal=%d\n", *(self->xVal));
- /* */
- }
- if (self->yVal) {
- *(self->yVal) += (int)((float)(hit->y * self->world.extent.y) /
- (float)self->clamp.extent.y) + self->world.orig.y;
- clamp(self->yVal, self->limits.orig.y, self->limits.extent.y);
- /* printf("selectValDelta: yVal=%d\n", *(self->yVal));
- /* */
- }
- }
-
-
- /*
- * process a selection on a floating point delta valuator
- */
- selectValDeltaf(self, argtype, hit)
- register valdeltaf *self;
- long argtype;
- register hitstruct *hit;
- {
- if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
- return;
-
- if (self->xVal) {
- *(self->xVal) += (((float)hit->x * self->world.extent.x) /
- (float)self->clamp.extent.x)+self->world.orig.x;
- clampf(self->xVal, self->limits.orig.x, self->limits.extent.x);
- /* printf("selectValDeltaf: xVal=%g\n", *(self->xVal));
- /* */
- }
- if (self->yVal) {
- *(self->yVal) += (((float)hit->y * self->world.extent.y) /
- (float)self->clamp.extent.y)+self->world.orig.y;
- clampf(self->yVal, self->limits.orig.y, self->limits.extent.y);
- /* printf("selectValDeltaf: yVal=%g\n", *(self->yVal));
- /* */
- }
- }
-
- /*
- * process a selection on a message valuator
- */
- selectValMesg(self, argtype, hit)
- register valmesg *self;
- long argtype;
- register hitstruct *hit;
- {
- if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
- return;
-
- self->val.x = (int)((float)(hit->x * self->world.extent.x) /
- (float)self->clamp.extent.x) + self->world.orig.x;
-
- self->val.y = (int)((float)(hit->y * self->world.extent.y) /
- (float)self->clamp.extent.y) + self->world.orig.y;
-
- /* printf("selectValMesg: val = %d, %d\n", self->val.x, self->val.y);
- /* */
-
- Msg(self->receiver, self->selector, PTR, &self->val);
- }
-
- /*
- * process a selection on a message valuator
- */
- selectValMesgf(self, argtype, hit)
- register valmesgf *self;
- long argtype;
- register hitstruct *hit;
- {
- if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
- return;
-
- self->val.x = ((float)(hit->x * self->world.extent.x) /
- (float)self->clamp.extent.x) + self->world.orig.x;
-
- self->val.y = ((float)(hit->y * self->world.extent.y) /
- (float)self->clamp.extent.y) + self->world.orig.y;
-
- /* printf("selectValMesgf: val=%g,%g\n", self->val.x, self->val.y); /* */
-
- Msg(self->receiver, self->selector, PTR, &self->val);
- }
-
- /*
- * process a selection on a valuator
- */
- selectValHue(self, argtype, hit)
- register valhue *self;
- long argtype;
- register hitstruct *hit;
- {
- colorPanel *dad;
-
- if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
- return;
-
- if (dad = (colorPanel *)self->base.dad) {
- dad->hue = (int)((float)(hit->x * self->world.extent.x) /
- (float)self->clamp.extent.x) + self->world.orig.x;
- printf("selectValHue: hue=%d\n", dad->hue);
- /* */
-
- dad->satur = (int)((float)(hit->y * self->world.extent.y) /
- (float)self->clamp.extent.y) + self->world.orig.y;
- printf("selectValHue: satur=%d\n", dad->satur);
- /* */
- }
- }
-
- /*
- * process a selection on a valuator
- */
- selectValVal(self, argtype, hit)
- register valhue *self;
- long argtype;
- register hitstruct *hit;
- {
- colorPanel *dad;
-
- if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
- return;
-
- if (dad = (colorPanel *)self->base.dad) {
- dad->value = (int)((float)(hit->y * self->world.extent.y) /
- (float)self->clamp.extent.y) + self->world.orig.y;
- printf("selectValHue: value=%d\n", dad->value);
- /* */
- }
- }
-
-
- /*
- * clamp hit point so that it lies within limiting box
- * and translate it to lie relative to the limiting box area
- */
- boxclamp(rectangle *bx, hitstruct *inpoint)
- {
- register returnval = 0;
-
- if (inpoint->x < bx->orig.x) {
- inpoint->x = bx->orig.x;
- returnval = 1;
- }
- if (inpoint->x > bx->extent.x + bx->orig.x) {
- inpoint->x = bx->extent.x + bx->orig.x;
- returnval = 1;
- }
-
- if (inpoint->y < bx->orig.y) {
- inpoint->y = bx->orig.y;
- returnval = 1;
- }
- if (inpoint->y > bx->extent.y + bx->orig.y) {
- inpoint->y = bx->extent.y + bx->orig.y;
- returnval = 1;
- }
-
- inpoint->x -= bx->orig.x;
- inpoint->y -= bx->orig.y;
-
- return returnval;
- }
-
- /*
- * clamp value pointed to so that it lies between lowlimit and hilimit
- */
- clamp(val, lowlimit, hilimit)
- int *val;
- int lowlimit, hilimit;
- {
- if (*val < lowlimit) *val = lowlimit;
- if (*val > hilimit) *val = hilimit;
- }
-
- /*
- * clamp floating point value so that it lies between lowlimit and hilimit
- */
- clampf(val, lowlimit, hilimit)
- Coord *val;
- Coord lowlimit, hilimit;
- {
- if (*val < lowlimit) *val = lowlimit;
- if (*val > hilimit) *val = hilimit;
- }
-